package com.atldy.commerce.config;

import com.alibaba.cloud.seata.web.SeataHandlerInterceptor;
import com.atldy.commerce.filter.LoginUserinfoInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @version 1.0
 * @Author: lidongyang
 * @CreateTime: 2021-08-11 22:54
 * @Description： web mvc配置
 */
@Configuration
public class EcommerceWebMvcConfig implements WebMvcConfigurer {

    /**
     * 拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginUserinfoInterceptor())
                .addPathPatterns("/**").order(0);
        //    配置seata拦截器，拦截xid
        registry.addInterceptor(new SeataHandlerInterceptor())
                .addPathPatterns("/**");
    }

    /**
     * 静态资源放行
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //配置swagger静态资源放行
        registry.addResourceHandler("/**").
                addResourceLocations("classpath:/static/");
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("doc.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
        WebMvcConfigurer.super.addResourceHandlers(registry);
    }
}